package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.PermsQuery;
import com.xingkeduo.pojo.table.PermsTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class PermsService {
    private static final String NAMESPACE = PermsTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<PermsTable, PermsQuery> dao;

    //查询一条
    public PermsTable selectById(long id) throws Throwable {
        PermsTable permsTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(permsTable))
            return permsTable;
        return null;
    }

    //查询多条
    public List<PermsTable> selectLists(PermsQuery permsQuery) throws Throwable {
        List<PermsTable> permsTableList = dao.select(NAMESPACE, permsQuery);
        if (!CommonUtil.isEmpty(permsTableList))
            return permsTableList;
        return null;
    }

    //分页查询
    public Page<PermsTable> selectPageLists(PermsQuery permsQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<PermsTable> permsTablePage = dao.pageSelect(NAMESPACE,permsQuery,pageNo,pageSize);
        return permsTablePage;
    }

    //插入
    public int insert(PermsTable permsTable) throws Throwable {
//        permsTable.setCode(IdentityUtil.nextId(Worker.USER));
        return dao.insert(NAMESPACE, permsTable);
    }

    //更新
    public int update(PermsTable permsTable) throws Throwable {
        return dao.update(NAMESPACE, permsTable);
    }

    //删除
    public int delete(PermsTable permsTable) throws Throwable {
        return dao.update(NAMESPACE, permsTable);
    }

}
